home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6102 < prev    next >
Encoding:
Text File  |  1996-08-05  |  10.9 KB  |  251 lines

  1. Path: qualcomm.com!usenet
  2. From: nababs@qualcomm.com (Nasser Abbasi)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ versus Ada "HELP"
  5. Date: 10 Feb 1996 14:49:29 GMT
  6. Organization: Qualcomm Inc.
  7. Message-ID: <4fib9p$5mc@qualcomm.com>
  8. References: <4fi5iu$50m@reader2.ix.netcom.com>
  9. NNTP-Posting-Host: nabbasi.qualcomm.com
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.93.14
  12.  
  13. In article <4fi5iu$50m@reader2.ix.netcom.com>, Markr123@ix.netcom.com 
  14. says...
  15. >
  16. >Can anyone tell me when it is better to use C++ versus Ada and why.  Has 
  17. >anyone ever seen any comparison article on this subject.  It is very 
  18. >important that I find some sort of information discribing the difference 
  19. >and similarities.  Please repost to this news group of directly to my 
  20. >E-mail at markr123@ix.netcom.com
  21. >
  22.  
  23. This is paper by Dr Tucker Taft on this subject. 
  24.  
  25. hope this helps.
  26.  
  27. Nasser
  28.  
  29. -------------------------------------
  30.  
  31. \begin{center}
  32. {\bf A Comparison of Ada, C, and C++}
  33.  
  34. S. Tucker Taft\\
  35. February 1995\\
  36. Copyright (C) 1995 Intermetrics, Inc.\\
  37. May be copied in whole or in part provided\\
  38. this source is credited.
  39. \end{center}
  40.  
  41. Ada 95 and C++ are very similar in terms of expressivity, but they
  42. differ in important ways as well.  Most fundamental is a difference in
  43. language design philosophy: In Ada, the building blocks of the
  44. language are all designed to be inherently safe and reliable, and a
  45. programmer who builds an abstraction using them automatically gains at
  46. least the same level of safety.
  47.  
  48. By contrast in C++, the building blocks of the language are by default
  49. unsafe, though the vigilant programmer can build safer abstractions
  50. out of these building blocks if they proceed carefully (though
  51. maintaining similar vigilance during maintenance can be difficult).
  52.  
  53. In other words, the fact that the Ada building blocks are both
  54. flexible and inherently reliable means that it takes less time and
  55. money for a programming team to reach the desired level of quality and
  56. reliability in a software system being developed in Ada, and that this
  57. level of quality and reliability is more likely to be retained during
  58. maintenance and enhancement.
  59.  
  60. The following table has a more detailed comparison of the various
  61. features of Ada, C, and C++.
  62.  
  63. {\bf 1) Separate Compilation and Library Management} 
  64.  
  65. Ada: An Ada compiler is required to enforce consistency and
  66. strong type checking across separate compilation.  The concept of
  67. a program library is built into the language, based on separately
  68. compilable modules called ``library units'' whose names are part of 
  69. a hierarchical name space.
  70.  
  71. C/C++: A C/C++ compiler only enforces consistency within
  72. a ``translation unit'' consisting of the include files and
  73. source files read in a single execution of the compiler.  
  74. Any additional consistency checking is relegated to third--party
  75. tools such as ``make,'' which are somewhat more susceptible
  76. to unintended versions skews.
  77.  
  78. {\bf 2) Portability}
  79.  
  80. Ada: Ada 95 is an ISO standard (ISO/IEC--8652:1995).  A large Ada
  81. Compiler Validation Capability (ACVC) suite exists, both for Ada 83
  82. and Ada 95; all commercial Ada 83 compilers are fully validated.  Many
  83. features of the language are designed to simplify the construction of
  84. highly portable programs.  For example, numeric types may be defined
  85. based on the required range of values, rather than relying on the
  86. possible meaning of type names like ``short int.''
  87.  
  88. C/C++: C is an ISO standard; C++ is a year or more from being an ISO
  89. standard.  At the present time, C++ compilers differ dramatically in
  90. the level of support for the various features of the language, meaning
  91. that portable programs can be difficult to construct.  Numeric type
  92. names (such as ``short int'') are hardware dependent, making it more
  93. difficult to create programs that are independent of a particular
  94. hardware platform.
  95.  
  96. {\bf 3) Arrays}
  97.  
  98. Ada: Arrays are ``first--class'' types in Ada.  The programmer can
  99. specify the type and the range of indices for a given array, and the
  100. compiler checks at compile--time for type consistency, and at run--time
  101. for array bounds consistency.  Assignment and slicing operations for
  102. arrays are provided, and the bounds of an array are automatically
  103. carried along as part of parameter passing.
  104.  
  105. C/C++: By default, pointer arithmetic is used to provide arrays in
  106. C/C++, with no type or bounds checking on indexing into an array.  No
  107. array assignment or slicing is provided.  No array bounds are carried
  108. along on parameter passing.  In C++, an array ``template'' can be used
  109. to provide more checking.
  110.  
  111. {\bf 4) Numerics}
  112.  
  113. Ada: Ada automatically detects and signals overflow for signed
  114. arithmetic operations.  A formal accuracy model is defined for
  115. floating point operations, with attributes that allow the programmer
  116. to query the available accuracy.  Numeric types may be chosen by the
  117. desired range or accuracy, rather than relying on target--specific
  118. names such as ``long float.''  Ada 95 provides wrap--around arithmetic
  119. via ``modular'' integer types, which include predefined operators for
  120. bit--wise and/or/xor/not.  Distinct user--defined numeric types may be
  121. used to provide compile--time protection against inappropriate adding
  122. of ``apples'' to ``oranges'' or equivalent, or using the wrong integer
  123. type as an index into an array.
  124.     
  125. C/C++: The effect of numeric overflow is undefined.  Numeric types
  126. must be chosen by name, rather than by required range or accuracy.
  127. The compiler silently converts between any two numeric types.
  128.  
  129. {\bf 5) Pointers}
  130.  
  131. Ada: Ada automatically initializes pointers to null, and detects any
  132. uses of null pointers.  Ada 95 allows pointers to declared objects;
  133. the compiler performs accessibility checks to ensure that dangling
  134. pointers are not created.
  135.  
  136. C/C++: In C/C++, pointers are not default initialized, and no checking
  137. is performed for uses of null pointers.  A pointer to a local stack
  138. object may be returned from a function, thereby creating a dangling
  139. pointer.
  140.  
  141. {\bf 6) Abstraction and Object--Oriented Programming (OOP)}
  142.  
  143. Ada: Ada 83 has full support for user--defined abstract data types via
  144. private types, encapsulation and information--hiding via packages, and
  145. compile--time polymorphism and type--parameterization via ``generic''
  146. units.  Ada 95 extends this support with full inheritance and run--time
  147. polymorphism of types, both for private types and record types.
  148. Packages remain the primary structuring, modularization, and
  149. information--hiding construct, allowing the programmer great
  150. flexibility in constructing their abstractions.
  151.  
  152. C/C++: C++ has full support for object--oriented programming.  C has
  153. essentially no language support for object--oriented (or even
  154. ``abstraction''--oriented) programming, though judicious use of macros
  155. and include files can accomplish some of the goals.
  156. Information--hiding is tied to classes in C++.  More recently, a
  157. separate modularization feature has been proposed for C++
  158. (``namespaces'') though it is not integrated with information--hiding.
  159.  
  160. {\bf 7) Concurrent and Real--Time Programming}
  161.  
  162. Ada: Ada includes concurrency support (multi--tasking) within the
  163. language.  All features of the language may be used safely in
  164. conjunction with multiple threads of control.  Specific features exist
  165. to support synchronization and real--time control of tasks.  Ada 95
  166. supports both message--oriented synchronization, via the rendezvous,
  167. and data--oriented synchronization, via protected types.  Ada 95
  168. provides support for asynchronous transfer of control, triggered by
  169. the completion of a specified time delay or by completion of an entry
  170. call.
  171.  
  172. C/C++: There is no direct support for concurrency in C or C++.  There
  173. are some coroutining class libraries available for C++, though the
  174. typical implementations of certain features of C++ (such as exception
  175. handling) are often not ``thread safe.''
  176.  
  177. {\bf 8) Generics}
  178.  
  179. Ada: Ada supports type parameterization (compile--time polymorphism)
  180. via generic units.  The specification of a generic unit contains all
  181. the information needed by the user (and the compiler) to determine
  182. whether any given instantiation of the generic will be legal (the
  183. so--called generic ``contract'' model).  New versions of a generic body
  184. can be incorporated without affecting the legality of existing
  185. instantiations.
  186.  
  187. C/C++: C provides syntax macros.  C++ includes a ``template'' facility
  188. which allows type parameterization.  There is no formal specification
  189. for the formal type parameters of a C++ template, meaning that the
  190. legality of an instantiation depends on the particular uses of the
  191. formal type parameters made within the code of the functions that
  192. implement the template.  This can result in incompatibilities when a
  193. new version of the implementation of a template is developed.
  194.  
  195. {\bf 9) Readability}
  196.  
  197. Ada: Part of the Ada ``culture'' is a strong concern for readability.
  198. The language encourages the use of meaningful names, and avoids use of
  199. cryptic special--character notations for the constructs and operators
  200. of the language.  All composite language constructs include an
  201. explicit ``end,'' thereby allowing the compiler to detect most
  202. single--token typing errors (such as omitting a semicolon).
  203.  
  204. C/C++: C and C++ make heavy use of special characters for language
  205. constructs and operators.  Declarations of pointers, arrays of
  206. pointers, pointers to functions, etc., make heavy use of asterisks,
  207. brackets, and nested parentheses.  Composite constructs do not require
  208. an explicit ``end,'' making single--token typing errors more likely to
  209. pass uncaught through the compiler.
  210. \newpage
  211.  
  212. {\bf 10) Compatibility}
  213.  
  214. Ada: Ada 95 is upward compatible with Ada 83, and its syntax and word
  215. order are easy for programmers familiar with Pascal, Modula, or Algol
  216. to understand.
  217.  
  218. C/C++: C++ is largely upward compatible with C, though at a detailed
  219. level, some different rules apply.  The syntax of C and C++ is unlike
  220. most other languages, and can be a source of errors (for example, the
  221. equality operator is ``=='' in C/C++, and a single ``='' causes an
  222. assignment, even when used in the test of an if--statement).
  223.  
  224. {\bf 11) Exception handling}
  225.  
  226. Ada: Ada supports exception handling.  In Ada 95, each occurrence of
  227. an exception carries along information specific to the particular
  228. error that occurred.  Failures of run--time checks are signaled by
  229. raising exceptions, which can then be handled just like user--defined
  230. exceptions.
  231.  
  232. C/C++: C has no support for exception handling.  In C++, exception
  233. handling is defined.  Any kind of object can be ``thrown'' as an
  234. exception.  There are no predefined exceptions for errors such as
  235. numeric overflow or null pointer dereference.
  236.  
  237. {\bf 12) User--defined operators}
  238.  
  239. Ada: Ada fully supports user--defined operators.  They are
  240. automatically inherited when one type is derived from another.  For
  241. binary operators, the left and right operands are treated
  242. symmetrically.
  243.  
  244. C/C++: C has no support for user--defined operators.  C++ supports
  245. user--defined operators, but because the left and right operands are
  246. not treated symmetrically for binary operators defined as member
  247. functions, most binary operators must be defined as ``friends'' of a
  248. class rather than as directly inheritable members of the class.
  249.  
  250.  
  251.